package com.woupla.navigation;

import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.seam.security.Identity;

import com.ocpsoft.pretty.PrettyContext;
import com.woupla.account.CurrentUserManager;
import com.woupla.account.UserType;

import java.io.Serializable;

@Named
@SessionScoped
public class DesktopMBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8540560314342596744L;
	private String page;
	@Inject
	private CurrentUserManager currentUserManager;
	@Inject
	private Identity identity;

	/**
	 * @return the page
	 */
	public String getPage() {
		return page;
	}

	/**
	 * @param page
	 *            the page to set
	 */
	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @return the currentUserManager
	 */
	public CurrentUserManager getCurrentUserManager() {
		return currentUserManager;
	}

	/**
	 * @param currentUserManager
	 *            the currentUserManager to set
	 */
	public void setCurrentUserManager(CurrentUserManager currentUserManager) {
		this.currentUserManager = currentUserManager;
	}

	public DesktopMBean() {
		// page="/desktop/info.xhtml";
		// page="/desktop/userGestion.xhtml";
	}

	public void showUsersGestion() {
		page = "/desktop/private/userGestion.xhtml";

	}

	public void showInfo() {

	}

	public void showInscription() {
		page = "/desktop/userInscription.xhtml";
	}

	public String showTemplate() {
		if (identity.isLoggedIn())
			return "/WEB-INF/templates/connected.xhtml";
		return "/WEB-INF/templates/notConnected.xhtml";
	}

	public boolean isDisabledSearchButton() {
		if (PrettyContext.getCurrentInstance().getCurrentMapping().getId().contentEquals("search"))
			return true;
		else
			return false;
	}

	public boolean isDisabledProfilButton() {
		if (PrettyContext.getCurrentInstance().getCurrentMapping().getId().contentEquals("profil"))
			return true;
		else
			return false;
	}

	public boolean isDisabledMySocietyButton() {
		if (PrettyContext.getCurrentInstance().getCurrentMapping().getId().contentEquals("society"))
			return true;
		else
			return false;
	}

	public boolean isRenderedMySocietyButton() {
		if (identity.isLoggedIn())
			if (currentUserManager.getCurrentAccount().getRole().contains(UserType.CUSTOMER.getValue()))
				return false;
			else
				return true;
		else
			return false;
	}
}
